from unittest import skip

from selenium.webdriver.common.by import By
from time import sleep, strftime
from ui_auto.public.pages.basepage import BasePage
from ui_auto.data.page_elem import Analysysdata_elem
from selenium.webdriver.support.wait import WebDriverWait


class Create_easy_sms(BasePage):
    @skip
    def test_sms_push(self):
        ea=BasePage.get_driver()
        now = strftime("%Y-%m-%d-%H-%M-%S")
        #进入创建sms页面
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.sms_list]))
        WebDriverWait(ea, 5).until(lambda _: ea.find_element(By.XPATH, Analysysdata_elem.create_sms_btn))
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.create_sms_btn]))
        #设置活动信息
        WebDriverWait(ea, 5).until(lambda _: ea.find_element(By.XPATH, Analysysdata_elem.input_sms_name))
        BasePage.sendkeys(BasePage.search_elem(['XPATH', Analysysdata_elem.input_sms_name]),"test_sms_"+now)
        BasePage.click(BasePage.search_elem(['XPATH',Analysysdata_elem.next_step_btn]))
        #目标用户
        WebDriverWait(ea, 5).until(lambda _: ea.find_element(By.XPATH, Analysysdata_elem.target_customer_text))
        BasePage.click(BasePage.search_elem(['XPATH',Analysysdata_elem.select_target_customer_segmention]))
        BasePage.sendkeys(BasePage.search_elem(['XPATH', Analysysdata_elem.search_customer_segmention]),"tianli")
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.target_customer]))
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.next_step_btn]))
        #触达人群
        WebDriverWait(ea, 5).until(lambda _: ea.find_element(By.XPATH, Analysysdata_elem.next_step_btn))
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.next_step_btn]))
        #发送内容
        WebDriverWait(ea, 5).until(lambda _: ea.find_element(By.XPATH, Analysysdata_elem.next_step_btn))
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.select_service_customer]))
        sleep(1)
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.dfnm_sms]))
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.select_template]))
        WebDriverWait(ea, 5).until(lambda _: ea.find_element(By.XPATH, Analysysdata_elem.easy_template))
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.easy_template]))
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.next_step_btn]))
        #发送sms
        WebDriverWait(ea, 5).until(lambda _: ea.find_element(By.XPATH, Analysysdata_elem.post_sms_btn))
        BasePage.click(BasePage.search_elem(['XPATH', Analysysdata_elem.post_sms_btn]))
        sleep(2)


